package com.rookie.im.message;

import java.io.UnsupportedEncodingException;
import java.util.Map;

import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.messaging.handler.annotation.Headers;
import org.springframework.messaging.handler.annotation.Payload;
import org.springframework.stereotype.Component;

import com.rabbitmq.client.Channel;
import com.rookie.im.utils.Constans;

@Component
public class ChatOperateReceiver {
	@RabbitListener(
			bindings = @QueueBinding(
					value = @Queue(value = Constans.RabbitmqConstans.Im2MessageService, durable = "true"),
					exchange = @Exchange(value=Constans.RabbitmqConstans.Im2MessageService, durable = "true")
					), concurrency = "1"
			)
	public void onChatMessage(
			@Payload Message message,
			@Headers Map<String, Object> headers,
			Channel channel
		) throws UnsupportedEncodingException {
		System.out.println(new String(message.getBody(), "utf-8"));
	}
}
